<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="cmd.css" rel="stylesheet" type="text/css">
<title>批处理实例菜单_3</title>
</head>

<body>
<p><a href="./GRUB4DOS11批处理实例菜单.htm">批处理实例脚本</a> <span class="Notes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span class="Notes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="./GRUB4DOS11批处理实例菜单_2.htm">批处理实例脚本_2</a> <span class="Notes">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>批处理实例脚本_3</p>
<h3><a href="http://bbs.wuyou.com/viewthread.php?tid=179738" target="_blank">SRSF6返回模块</a> (by zhaohj@wuyou) 中的部分批处理脚本</h3>
<p><strong>1、后移硬盘，便于全外置PE使用</strong></p>
<p><span class="Options">!BAT</span><br>
  <span class="bat">set</span> <span class="Options">/a</span><strong> hd=*0x475</strong><span class="Options">&amp;</span><strong>0xff</strong><span class="Options">+</span><strong>0x7f</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;内存地址0x475的低2字节保存的是物理磁盘数，使用 &quot;*0x475&amp;0xff&quot; 即可得到磁盘数，<br>
  ::&nbsp;&nbsp;&nbsp;将这个结果与0x7f相加后即为最后一块磁盘的驱动器号，并将这个值赋给变量 hd ，<br>
  ::&nbsp;&nbsp;&nbsp;以含有两块物理磁盘为例(hd0) (hd1)，执行本行命令后变量 hd 值为129 （16进制的 0x81），<br>
  ::&nbsp;&nbsp;&nbsp;此时 hd0 为 128 (0x80) 号设备， hd1 为 129 (0x81) 号设备</span><br>
  <span class="bat">checkrange</span> <strong>0x7f </strong><span class="bat">calc</span> <strong>%hd%</strong> <span class="Options">&amp;&amp;</span> <span class="bat">exit</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;若变量 hd 的值大于0x7f，说明存在物理磁盘，否则不存在物理磁盘，退出本脚本</span><br>
  <span class="cmd">:move</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，方便循环处理</span><br>
  <span class="bat">set</span> <span class="Options">/A</span> <strong>hd1=%hd%</strong><span class="Options">+</span><strong>1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 hd 的值加一后赋给新变量 hd1，此时值为 0x82</span><br>
  <span class="bat">map</span> <strong>(%hd%) (%hd1%)</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将最后一块磁盘向后移，初始时 hd0 为  0x80号设备， hd1 为 0x81号设备，<br>
  ::&nbsp;&nbsp;&nbsp;此时 hd0 为 0x80 号设备， hd1 为 0x82 号设备 </span><br>
  <span class="bat">set</span> <span class="Options">/A</span> <strong>hd=%hd%-1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 hd 的值减一后重新赋给变量 hd，准备处理下一块磁盘</span><br>
  <span class="bat">checkrange</span> <strong>0x7f </strong><span class="bat">calc</span> <strong>%hd%</strong> <span class="Options">||</span> <span class="bat">goto</span> <strong>:move</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;判断是否已处理完最后一块磁盘，没有的话返回到 :move 标签继续后移磁盘，<br>
  ::&nbsp;&nbsp;&nbsp;本例中需执行两次后移磁盘操作，执行完毕后hd0为 0x81 号设备，hd1为 0x82 号设备，<br>
  ::&nbsp;&nbsp;&nbsp;并保留原hd0设备号 (0x80) 不变以便供全外置内核PE使用</span><br>
  <span class="bat">map</span><span class="Options"> --hook</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;使仿真生效</span><br>
  <span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理脚本</span></p>
<p>目的是腾出hd0供PE使用，这样PE不会搞乱硬盘,可以使用在CSPE及OPE</p>
<p>------------------------------------------------------------------------------------</p>
<p><strong>2、下面实现变量对齐,使输出效果比较美观</strong></p>
<p>声明：下面的图中 firax=fira-x86 , srs=SYMMPI</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;此批处理目的要使[%firax%]与[%srs%]长度一样</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显然，%firax%的长度是8，%srs%的长度是6</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这样[%srs%]要变成[ SYMMPI ]</p>
<p>此批处理二个要点：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1：变量值长度的计算</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2：变量值追加空格怎么实现（转义符的使用）</p>
<p><span class="Options">!BAT</span><br>
  <strong>...</strong><br>
  <span class="bat">set </span><strong>a=%firax%</strong> <span class="Options">&amp;&amp;</span> <span class="bat">set</span> <span class="Options">/a</span> <strong>len1=*0x4cb00</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 firax 的值赋给变量 a ，并将该值长度转换为10进制赋给变量 len1<br>
  ::&nbsp;&nbsp;&nbsp;内存地址0x4cb00处存放的是变量长度</span><br>
  <span class="bat">call</span> <strong>:blank %len1%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len1 的值作为参数传递给 :blank 标签段脚本执行</span><br>
  <span class="bat">set </span><strong>empty=[%b%]</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 b 的值加上中括号后赋给变量 empty （仅仅是为了美观）</span><br>
  <span class="bat">echo</span> <span class="Options">-e</span> <strong>%empty%</strong> <span class="Options">|</span> <span class="bat">set</span> <strong>empty=</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将 \x20 转义为空格，将新值重新赋给变量 empty</span><br>
  <span class="bat">set </span><strong>a=%srs%</strong> <span class="Options">&amp;&amp;</span><span class="bat"> set</span> <span class="Options">/a</span> <strong>len2=*0x4cb00<br>
  </strong><span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 srs 的值赋给变量 a ，并将该值长度转换为10进制赋给变量 len2</span><br>
  <span class="bat">set</span> <span class="Options">/a</span><strong> len1=%len1%<span class="Options">-</span>%len2%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len1 的值和变量 len2 的值相减后重新赋给变量 len1</span><br>
  <span class="bat">checkrange</span> <strong>1:-1</strong> <span class="bat">calc</span> <strong>%len1%</strong> <span class="Options">||</span> <span class="bat">set</span> <strong>srs=[%srs%] </strong><span class="Options">&amp;&amp;</span> <span class="bat">goto</span><strong> :start</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;若变量 len1 的值为0，则将变量 srs 的值加中括号后重新赋给变量 srs，并跳转至 :start 标签执行<br>
  ::&nbsp;&nbsp;&nbsp;否则，继续执行</span><br>
  <span class="bat">set</span> <span class="Options">/a</span> <strong>len2=%len1%/2</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len1 的值除以2，然后取整赋给变量 len2</span><br>
  <span class="bat">set</span> <span class="Options">/a</span> <strong>len1=%len1%<span class="Options">-</span>%len2%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len1 的值和变量 len2 的值相减后重新赋给变量 len1</span><br>
  <span class="bat">call </span><strong>:blank %len2%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len2 的值作为参数传递给 :blank 标签段脚本执行</span><br>
  <span class="bat">set</span> <strong>srs=[%b%%%srs%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将新值赋给变量 srs</span><br>
  <span class="bat">call </span><strong>:blank %len1%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 len1 的值作为参数传递给 :blank 标签段脚本执行 </span><br>
  <span class="bat">set </span><strong>srs=%srs%%%b%]</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将新值赋给变量 srs</span><br>
  <span class="bat">echo</span> <span class="Options">-e</span> <strong>%srs%</strong> <span class="Options">|</span> <strong>set srs=</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 srs 中的 \x20 全部转义为空格，并将新值重新赋给变量 srs<br>
  ::&nbsp;&nbsp;&nbsp;至此美化完成，最终效果可见下图</span><br>
  <span class="cmd">:start</span><br>
  <strong>......</strong><br>
  <span class="bat">exit</span></p>
<p><span class="cmd">:blank</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名</span><br>
  <span class="bat">set</span> <span class="Options">/a</span> <strong>a=%1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将参数1作为值赋给变量 a</span><br>
  <span class="bat">set</span><strong> b=</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;清除变量 b</span><br>
  <span class="cmd">:next</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，方便循环处理</span><br>
  <span class="bat">if </span><strong>%a%==0</strong> <span class="bat">exit</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;如果变量 a 的值是 0 的话就中止本段脚本执行，返回原处继续执行</span><br>
  <span class="bat">set</span> <span class="Options">/a</span> <strong>a=%a%<span class="Options">-</span>1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将变量 a 的值减一后重新赋给变量 a</span><br>
  <span class="bat">set</span> <strong>b=%b%\x20</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;\x20转义后为一个空格，此处不转义，只是将其赋给变量 b<br>
::&nbsp;&nbsp;&nbsp;变量赋值，空格是无效的，所以空格先使用\x20代替<br>
  ::&nbsp;&nbsp;&nbsp;本段脚本执行了几次，变量 b 就是几个空格</span><br>
  <span class="bat">goto</span> <strong>:next</strong><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;返回 :next 标签继续执行</span></p>
<p>&nbsp;</p>
<p>最终效果可见图</p>
<p><img src="ps1.jpg" width="566" height="298"><br>
</p>
</body>
</html>
